<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<%@ page import="java.util.*" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.activiti.engine.ProcessEngine" %>
<%@ page import="org.activiti.engine.RepositoryService" %>
<%@ page import="org.activiti.engine.identity.User" %>
<%@ page import="org.activiti.engine.repository.Deployment" %>
<%@ page import="com.JavascriptMessage" %>
<%@ page import="com.DateUtil" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link type="text/css" rel="stylesheet" charset="utf-8" href="<%=request.getContextPath() %>/css/base.css"/>
<title>Deployment</title>
</head>
<%
User user = (User)session.getAttribute("user");
String doWhat = request.getParameter("doWhat");
String message = null;

WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
//ProcessEngine engine = (ProcessEngine)context.getBean("processEngine");
RepositoryService repository = (RepositoryService)context.getBean("repositoryService");

if(doWhat != null && doWhat.equals("delete")){
	repository.deleteDeployment(request.getParameter("deploymentId"), true);
	message = "delete deployment success...";
}

List<Deployment> list = repository.createDeploymentQuery().orderByDeploymenTime().desc().list();
%>
<body>
<%if(message != null){out.write(JavascriptMessage.alert(message));}%>
<table align="center" width="100%">
	<caption>Deployment</caption> 
	<tr>
		<th align="center" scope="col">Id</th>
		<th align="center" scope="col">Name</th>
		<th align="center" scope="col">DeploymentTime</th>
		<th align="center" scope="col"></th>
	</tr>
	<%for(Deployment d : list){%>
	<tr>
		<td class="row"><%=d.getId() %></td>
		<td class="row"><%=d.getName() %></td>
		<td class="row"><%=DateUtil.format(d.getDeploymentTime(),"yyyy-MM-dd HH:ss") %></td>
		<td class="row"><a href="<%=request.getContextPath() %>/jsp/deployment.jsp?doWhat=delete&deploymentId=<%=d.getId() %>">delete</a></td>
	</tr>
	<%} %>
</table>
</body>
</html>